const Router = require('koa-router')
const md5 = require('blueimp-md5')


const router = new Router()


router.get('/', async (ctx, next)=>{
  await ctx.render('index', {title:'EJS'})

})


router.post('/register', (ctx, next)=>{
  console.log(ctx.request.body)
  ctx.cookies.set('name', 'jack', {maxAge:60*60*1000*24*3})

  ctx.body = {
    name: 'Jack'
  }

})

router.post('/login', (ctx, next)=>{
  const {uname, passwd} = ctx.request.body

  ctx.cookies.set('uname', uname)
  ctx.cookies.set('passwd', passwd)

  ctx.body = {
    success: true,
    code: 200,
    data: {
      uname,
      passwd
    }
  }
})


module.exports = router
